package pictureTCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(10010);
        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("after_buy\\yfz.jpg"));
        byte[] bytes = new byte[1024];
        int len;
        while((len=is.read(bytes))!=-1) {
            bos.write(bytes,0,len);
        }
        bos.close();
        //告知客户端上传成功
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("上传成功啦");
        bw.newLine();
        bw.flush();
        //给客户端写一个结束标记
        socket.shutdownOutput();
    }
}
